package com.cqc.manage.service.Imp.business;


import com.cqc.manage.entity.Business;
import com.cqc.manage.entity.MessageBusiness;
import com.cqc.manage.entity.User;
import com.cqc.manage.repositories.MessageBusinessRepositories;
import com.cqc.manage.service.Imp.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.UUID;

@Service
public class EngineerBusinessService {


    @Autowired
    private MessageBusinessRepositories messageBusinessRepositories;
    @Autowired
    private UserService userService;


    /**
     * 分配业务
     * @param business  业务对象
     * @param engineerID   工程师id
     */
    public void DistributionBusiness(Business business,String engineerID){
        MessageBusiness engineerBusiness = new MessageBusiness();
        User user = userService.queryByUserId(engineerID);
        engineerBusiness.setEngineer(user.getUserName());
        engineerBusiness.setEngineerId(engineerID);
        engineerBusiness.setEndDate(business.getEndDate());
        engineerBusiness.setDistributionDate(new Date());
        engineerBusiness.setClient(business.getClient());
        engineerBusiness.setId(UUID.randomUUID().toString().replace("-",""));
        engineerBusiness.setChargeNotice(false);
        engineerBusiness.setContractNo(business.getContractNo());
        engineerBusiness.setStandard(business.getStandard());
        engineerBusiness.setReportType(business.getReportType());
        engineerBusiness.setStartDate(business.getStartDate());
        engineerBusiness.setSampleModel(business.getSampleModel());
        engineerBusiness.setSampleCategory(business.getSampleCategory());
        engineerBusiness.setCompleteFlat(false);
        engineerBusiness.setIncompleteFlat(true);
        messageBusinessRepositories.save(engineerBusiness);
    }



}
